package com.ebspp.server;

import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;

import com.ebspp.global.General;
import com.ebspp.thrift.GarbageCollect;

/**
 * garbage collecting the data in itself
 * It is based on threadPool, each garbage collection connection has its thread
 * @author x23pan
 *
 */
public class EBSPPGarbageServer {

	public static void initServer()
	{	 
		try 
		{
			TServerSocket serverTransport = new TServerSocket(General.gbPort);
			
			GarbageCollect.Processor processor = new GarbageCollect.Processor(new GarbageHandler());

			TServer server = new TThreadPoolServer(
								new TThreadPoolServer.Args(serverTransport).processor(processor));
			
			System.out.println("Start garbage collection server at port: " + General.gbPort);
			
			server.serve();
			System.err.println("Write server closed");
		} catch (TTransportException e) {
			// TODO Auto-generated catch block
			System.err.println("Error: Write server closed");
			e.printStackTrace();
		}
	}
}
